#include <iostream>
#include <map>
#include <set>
#include <c++/vector>

using namespace std;

class FoodRatings {
    map<string,pair<int,string>> fs;//食物名字->(评分，烹饪方式)
    map<string,set<pair<int,string>>> cs;//烹饪方式->set(评分，名字)
public:
    //foods:食物名字
    //cuisines:烹饪方式
    //ratings:评分
    FoodRatings(vector<string>& foods, vector<string>& cuisines, vector<int>& ratings) {
        for (int i = 0; i < foods.size(); ++i) {
            auto &f = foods[i];
            auto &c = cuisines[i];
            int r=ratings[i];
            fs[f]={r,c};
            cs[c].emplace(-r,f);//保证最小的对应的部分是最高的部分
        }
    }
    void changeRating(string food, int newRating) {
        auto &[r,c]=fs[food];
        auto &s=cs[c];
        //把旧的删除了
        s.erase({-r,food});
        //把新的加到set
        s.emplace(-newRating,food);
        //修改评分
        r=newRating;
    }

    string highestRated(string cuisine) {
        return cs[cuisine].begin()->second;
    }
};

int main(){
    vector<string> foods={"kimchi", "miso", "sushi", "moussaka", "ramen", "bulgogi"};
    vector<string> cuisines={"korean", "japanese", "japanese", "greek", "japanese", "korean"};
    vector<int> ratings={9, 12, 8, 15, 14, 7};
    FoodRatings foodRatings(foods,cuisines,ratings);
    cout<<foodRatings.highestRated("japanese")<<endl;
    foodRatings.changeRating("sushi", 16);
    cout<<foodRatings.highestRated("japanese")<<endl;
    foodRatings.changeRating("ramen", 16);
    cout<<foodRatings.highestRated("japanese")<<endl;
    return 0;
}